import axios from "../utils/http";

const GoodsStore = {
    namespaced: true,
    state: () => ({
        goods_list: [],
        zhongshu:0
    }),
    mutations: {
        GoodsMutations(state, list) {
            state.goods_list = list
        },
        GoodsZhongshuMU(state,total){
            state.zhongshu=total
        }
    },
    actions: {
        GoodsActions(context, page = { page:1, size: 5 }) {
            let url = '/api/goodslist?page=' + page.page + '&size=' + page.size
            axios.get(url).then(res => {
                if (res.code == 200) {
                    console.log(res);
                    context.commit('GoodsMutations', res.list)
                }
            })
        },
        GoodsZhongshu(context){
            axios.get('/api/goodscount').then(res=>{
                 if(res.code==200){
                     console.log(res.list[0].total);
                    context.commit('GoodsZhongshuMU',res.list[0].total)
                 }
            })
        }
    }
}

export default GoodsStore